class Solution {
    int m, n;
    int dx[8] = { 0, 0, 1, -1, -1, 1, 1, -1 }, dy[8] = { -1, 1, 0, 0, -1, 1, -1, 1 };
    vector<vector<int>> ret;
    int helper(int x, int y, vector<vector<int>>& img)
    {
        int sum = img[x][y], cnt = 1;
        for(int i = 0; i < 8; i++)
                if(x + dx[i] >= 0 && x + dx[i] < m && y + dy[i] >= 0 && y + dy[i] < n)
                {
                    sum += img[x + dx[i]][y + dy[i]];
                    cnt++;
                }
        // cout << sum << endl;
        // cout << cnt << endl;
        // cout << "---------------------------\n";
        return floor(sum / cnt);
    }
public:
    vector<vector<int>> imageSmoother(vector<vector<int>>& img) {
        m = img.size(), n = img[0].size();
        ret = vector<vector<int>>(m, vector<int>(n, 0));
        for(int i = 0; i < m; i++)
            for(int j = 0; j < n; j++)
                ret[i][j] = helper(i, j, img);
        return ret;
    }
};